# -*- Mode: Makefile;  -*-

# this makefile contains the basic rules and scripts for a multidim build.

# variables which must be defined by the makefile including this file are:
#
# CHOMBO_HOME : location of the Chombo lib directory (normally one directory
#               up from the location of this file)
#
# MULTIDIM_MAKEFILE: file (normally in the directory where the build is
#                    taking place) which contains the libraries and source
#                    directory information required for a multidim build.
#
# MINDIM : smallest dimension required for this build
# MAXDIM : highest dimension required for this build
#
# ebase : target in the MULTIDIM_MAKEFILE which builds the example 
#         (normally also the root of the executable)
#
# 

# this target is here mostly to ensure that if a default target is not 
# defined in the makefile which is including this one, that the default
# target isn't "realclean", which would be a bit inconvenient 
usage:
	@echo "This makefile supports targets:"
	@echo "     all-multidim realclean clean example-only  $(ebase) usage"


realclean:
	$(MAKE) -f $(MULTIDIM_MAKEFILE) realclean NODEPENDS=TRUE

clean:
	$(MAKE) -f $(MULTIDIM_MAKEFILE) clean NODEPENDS=TRUE


all-multidim: $(CHOMBO_HOME)/src/BoxTools/BoxTools_ExternC_Mangler.H
	mdebase=$(ebase); \
	\
	compileOptions="mdebase=$${mdebase} "; \
	compileOptions="USE_MT=FALSE $${compileOptions}"; \
	if [ ! -e $(CHOMBO_HOME)/include/multidim ]; then \
	  mkdir $(CHOMBO_HOME)/include/multidim; \
	fi; \
	\
	echo "building libraries..."; \
	\
	dimflags=""; \
	\
	iDim=$(MINDIM); \
	dimFlags=""; \
	while [ $${iDim} -le $(MAXDIM) ]; \
	do \
	  echo "DIM = $${iDim} -- stepping into sub-make in $(MULTIDIM_MAKEFILE)"; \
	  $(MAKE) -f $(MULTIDIM_MAKEFILE) lib $${compileOptions} NAMESPACE=TRUE MULTIDIM=TRUE DIM=$${iDim}; \
	  \
	  dimFlags="$${dimFlags} USE_$${iDim}D=TRUE"; \
	  \
	  iDim=`expr $${iDim} + 1`; \
	done; \
	\
	echo "installing include files..."; \
	\
	backdir=`pwd`; \
	cd $(CHOMBO_HOME); \
	$(MAKE) include $${compileOptions} MULTIDIM=TRUE NAMESPACE=TRUE; \
	cd $${backdir}; \
	\
	$(MAKE) -f $(MULTIDIM_MAKEFILE) $${mdebase} $${compileOptions} $${dimFlags} DIM=0 MULTIDIM=TRUE NAMESPACE=TRUE


all-multidim-nolibs: 
	mdebase=$(ebase); \
	\
	compileOptions="mdebase=$${mdebase} "; \
	compileOptions="USE_MT=FALSE $${compileOptions}"; \
	\
	dimflags=""; \
	\
	iDim=$(MINDIM); \
	dimFlags=""; \
	  $(MAKE) -f $(MULTIDIM_MAKEFILE) createDependencies $${compileOptions} NAMESPACE=TRUE MULTIDIM=TRUE DIM=$${iDim}; \
	while [ $${iDim} -le $(MAXDIM) ]; \
	do \
	  dimFlags="$${dimFlags} USE_$${iDim}D=TRUE"; \
	  \
	  iDim=`expr $${iDim} + 1`; \
	done; \
	\
	$(MAKE) -f $(MULTIDIM_MAKEFILE) $${mdebase} $${compileOptions} $${dimFlags} DIM=0 MULTIDIM=TRUE NAMESPACE=TRUE



example-only: all
	$(MAKE) -f GNUmakefile.regression mdebase=$(ebase) regression

$(CHOMBO_HOME)/src/BoxTools/BoxTools_ExternC_Mangler.H: $(CHOMBO_HOME)/src/BoxTools/multidim/extern.list
	cd $(CHOMBO_HOME)/..; ./bootstrap




